//
//  NSVipHeaderView.m
//  Meboo
//
//  Created by kyo on 2024/3/13.
//

#import "NSVipHeaderView.h"
@interface NSVipHeaderView ()
@property (nonatomic, strong) UIButton *leftBtn;

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *backImageView;
@property (nonatomic, strong) UIImageView *vipNameLab;
@property (nonatomic, strong) UILabel *vipDetailLab;
@end

@implementation NSVipHeaderView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Action
- (void)leftAction {
    [self.currentViewController.navigationController popViewControllerAnimated:YES];;
}

- (void)resetVipDate {
    self.dateLab.text = [NSString stringWithFormat:@"Until: %@",[MBUserAccount defaultAccount].vipDateStr];
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.backImageView];
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.mas_top).offset(StatusBarAndNavigationBarHeight-MBHeightScale(8));
    }];
    
    [self addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(20));
        make.centerY.equalTo(self.titleLab);
        make.width.height.mas_equalTo(MBHeightScale(20));
    }];
    
    [self addSubview:self.dateLab];
    [self.dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(MBHeightScale(-39));
        make.left.mas_equalTo(MBWidthScale(44));
    }];
    
    [self addSubview:self.vipDetailLab];
    [self.vipDetailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.dateLab.mas_top).offset(MBHeightScale(-21));
        make.left.mas_equalTo(MBWidthScale(44));
        make.width.mas_equalTo(MBWidthScale(130));
    }];
    
    [self addSubview:self.vipNameLab];
    [self.vipNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.vipDetailLab.mas_top).offset(MBHeightScale(-8));
        make.left.mas_equalTo(MBWidthScale(44));
//        make.width.mas_equalTo(MBWidthScale(106));
//        make.height.mas_equalTo(MBWidthScale(106)/106*22);
    }];
}

#pragma mark - Setter && Getter
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [[UIButton alloc] init];
        [_leftBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_leftBtn setImage:ImageWithName(@"back_arrow_black") forState:0];
        [_leftBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = MBHelFontSizeScale(20);
        _titleLab.textColor = HEXS(@"000000");
        _titleLab.text = @"Member Activation";
    }
    return _titleLab;
}

- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.image = [UIImage imageNamed:@"mine_vip_topback"];
    }
    return _backImageView;
}

- (UIImageView *)vipNameLab {
    if (!_vipNameLab) {
        _vipNameLab = [[UIImageView alloc] init];
        _vipNameLab.image = ImageWithName(@"mine_vip_vipaccount");
    }
    return _vipNameLab;
}

- (UILabel *)vipDetailLab {
    if (!_vipDetailLab) {
        _vipDetailLab = [[UILabel alloc] init];
        _vipDetailLab.numberOfLines = 2;
        _vipDetailLab.font = MBHelFontSizeScale(14);
        _vipDetailLab.textColor = HEXS(@"544379");
        _vipDetailLab.text = @"Get access to\nPremium features";
    }
    return _vipDetailLab;
}

- (UILabel *)dateLab {
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.textAlignment = NSTextAlignmentCenter;
        _dateLab.font = MBHelFontSizeScale(16);
        _dateLab.textColor = HEXS(@"FF552D");
        if ([MBUserAccount defaultAccount].isVip) {
            _dateLab.text = [NSString stringWithFormat:@"Until:%@",[MBUserAccount defaultAccount].vipDateStr];
        }
    }
    return _dateLab;
}
@end
